Java Exceptions Tutorials With Examples

Exceptions are nothing but some anomalous conditions that occur during the execution of the program. Exceptions are the conditions or typically an event which may interrupt the normal flow of the program's instructions.

Java Exceptions Tutorials With Examples

Exceptions are nothing but some anomalous conditions that occur during the execution of the program. Exceptions are the conditions or typically an event which may interrupt the normal flow of the program's instructions.

Java Exceptions Tutorials With Examples

Java Exceptions Tutorials With Examples

     

  1. Exceptions in Java
    Exceptions are nothing but some anomalous conditions that occur during the execution of the program. Exceptions are the conditions or typically an event which may interrupt the normal flow of the program's instructions. 
      
  2. Exception Classes
    The hierarchy of exception classes commence from Throwable class which is the base class in java.lang. This class can be instantiated and thrown by the program. The Throwable class is further divided into two subclasses :- 
            
  3. Catching and Handling Exceptions
    The three exception handler components are used to catch and handle the exceptions. These are try, catch and finally clause. The mechanism to catch an exception in Java is to use try and catch block.
  4.     
  5. How to Throw Exceptions
    Before catching an exception it is must to be thrown first. This means that there should be a code somewhere in the program that could catch the exception.
  6.     
  7. Handling Multiple Catch Clauses
     In java when we handle the exceptions then we can have multiple catch blocks for a particular try block to handle many different kind of exceptions that may be generated while running the program.
  8.       
  9. Nested Try-Catch Blocks
    In Java we can have nested try and catch blocks. It means that, a try statement can be inside the block of another try.
      
  10. Catching Normal Exceptions
    The exceptions that are generated by methods are referred to as normal exceptions.  We have already learned that to catch an exception we use try and catch block.
  11.     
  12. Making Custom (User Defined) Exceptions
     
    If you encounter a situation where none of those exception describe your exception accurately or if you can't find the appropriate exception in the Java API, you can code a class that defines an exception that is more appropriate
  13.    
  14. What are Chained Exceptions
    Chained exceptions are the exceptions which occur one after another i.e. most of the time to response to an exception is given by an application by throwing another exception.
  15.      
  16. How to Print a Stack Trace Message
    Instead of this this method you can get more information about the error process if you print a stack trace from the exception using the printStackTrace() method that prints the stack trace to the console